
#include <BFont>
#include <BStyle>
#include "member_BMessageBox.h"

using namespace BWE;

member_BMessageBox::member_BMessageBox(BMessageBox* messageBox)
{
	boss = messageBox;
	textAlign = Align_None;
	lineFeed = true;

	dirty = false;
	styleIcon = Icon_None;
	defaultButton = Button_None;
}
member_BMessageBox::~member_BMessageBox()
{

}

const char* member_BMessageBox::buttonText(Button button)
{
	switch (button)
	{
	case Button_None:
		return "None";
	case Button_Left:
		return "Left";
	case Button_Middle:
		return "Middle";
	case Button_Right:
		return "Right";
	case Button_Ok:
		return "OK";
	case Button_Open:
		return "Open";
	case Button_Save:
		return "Save";
	case Button_Confirm:
		return "Confirm";
	case Button_Cancel:
		return "Cancel";
	case Button_Apply:
		return "Apply";
	case Button_Reset:
		return "Reset";
	case Button_Retry:
		return "Retry";
	case Button_Yes:
		return "Yes";
	case Button_No:
		return "No";
	case Button_Next:
		return "Next";
	case Button_Prev:
		return "Prev";
	case Button_Continue:
		return "Continue";
	case Button_Ignore:
		return "Ignore";
	case Button_Help:
		return "Help";
	case Button_Abort:
		return "Abort";
	case Button_Hide:
		return "Hide";
	case Button_Close:
		return "Close";
	case Button_Minimize:
		return "Minimize";
	case Button_Maximize:
		return "Maximize";
	case Button_Normalize:
		return "Normalize";
	default:
		return 0;
	}

}

void member_BMessageBox::freshRects()
{
	const BStyle* style = boss->realStyle();
	if (style)
		style->translate(text, block.text);
	if (block.text.empty())
		block.text = text;
	block.reset();
	block.setStyle(style);
	block.font = style->font();
	block.dirty = true;
	block.adjust(0);
	textSize = block.size();
	BRect crect = boss->centerRect();
	if (lineFeed)
		block.adjust(crect.width());
	else
		block.adjust(0);
	block = crect.align(textAlign, block.size());
}

void member_BMessageBox::slotButtonClicked(BObject* object)
{
	BButton* btn = dynamic_cast<BButton*>(object);
	for (int i = 0; i < buttons.size(); i++)
	{
		if (buttons[i] == btn)
		{
			boss->close(buttons[i]->asset());
			break;
		}
	}
}

